libgdx loading textures fails [duplicate]

Posted by Chris on Game Development See other posts from Game Development or by Chris
Published on 2013-10-18T15:24:31Z Indexed on 2013/10/18 16:15 UTC
Read the original article Hit count: 235

Filed under:

This question already has an answer here:

I'm trying to load my texture with

playerTex = new Texture(Gdx.files.internal("player.jpg"));

player.jpg is located under my-gdx-game-android/assets/data/player.jpg

I get an exception like this: enter image description here

Full Code:

@Override
public void create() {      
    camera = new OrthographicCamera();
    camera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());        

    batch = new SpriteBatch();
    FileHandle file = Gdx.files.internal("player.jpg");
    playerTex = new Texture(file);

    player = new Rectangle();
    player.x = 800-20;
    player.y = 250;
    player.width = 20;
    player.height = 80;
}

@Override
public void dispose() {
    // dispose of all the native resources
    playerTex.dispose();
    batch.dispose();
}

@Override
public void render() {      
    Gdx.gl.glClearColor(1, 1, 1, 1);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    camera.update();

    batch.setProjectionMatrix(camera.combined);
    batch.begin();
    batch.draw(playerTex, player.x, player.y);
    batch.end();

    if(Gdx.input.isKeyPressed(Keys.DOWN)) player.y -= 50 * Gdx.graphics.getDeltaTime();
    if(Gdx.input.isKeyPressed(Keys.UP)) player.y += 50 * Gdx.graphics.getDeltaTime();
}

© Game Development or respective owner

Related posts about libgdx